home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / dottyplot.c next >
Text File  |  1996-07-05  |  4KB  |  135 lines

  1. /* dottyplot.c -- c version of dotplot routine 
  2.  
  3.     by d.g.gilbert May 1989
  4.     MWP-C compiler
  5.     
  6.     !! revise to do line segments along diagonals
  7.         that have contiguous points
  8.     ! add event check to cancel loop if user is leaning
  9.         on cmd-. key  (see other MPW tool samples)
  10.         
  11. --------------------------------------*/
  12.  
  13. #include <Values.h>
  14. #include <Types.h>
  15. #include <QuickDraw.h>
  16. #include <ToolUtils.h>
  17. #include <Memory.h>
  18. #include <OSUtils.h>
  19. #include    <CursorCtl.h>
  20.  
  21.  
  22. #define min(a,b)  (a<b)?a:b
  23. #define max(a,b)    (a>b)?a:b
  24.  
  25.         
  26.             
  27. pascal void windowpt( char *vseq, unsigned short nv, 
  28.                                             char *hseq, unsigned short nh,
  29.                                             unsigned short window, 
  30.                                             unsigned short nmatch, 
  31.                                             char doself, 
  32.                                             char allpts, 
  33.                                             long **pich) 
  34.     {
  35.         register char *matchp, *hp, *vp;
  36.         register int    i;
  37.         char        *matchvec;
  38.         int          matches, diag, xstart, ystart, yfinish, halfwind, 
  39.                       h, v, ndiag, j, lasti, n2;
  40.         long        npic, maxpic;
  41.  
  42.  
  43. /************ !!?? define don't work !!
  44. #define dodot(k)        {             \
  45.         if (npic >= maxpic) {        \ 
  46.             maxpic += 100;              \
  47.             SetHandleSize((Handle)pich, maxpic*sizeof(long)); \
  48.             if (MemError() != 0) goto done;    \
  49.             }        \
  50.         (*pich)[npic++] = (h+k) + ((v-k)<<16); \     
  51.         }
  52.  ***********/
  53.         
  54.         /* InitCursorCtl(nil); -- do in caller */
  55.         matchvec = NewPtr( nv+window+10);
  56.         n2= nh+nv-1;
  57.          halfwind = window >> 1;
  58.         
  59.         maxpic    = GetHandleSize((Handle)pich) / sizeof(long);
  60.         npic        = 0;
  61.         
  62.                 /* Compare for each register shift (diagonal) */
  63.         if (doself) ndiag= nv; else ndiag = n2;
  64.         for (diag=1; diag<=ndiag; diag++) {
  65.             RotateCursor(diag);
  66.           ystart=  max(0, nv-diag);
  67.             yfinish= min( nv-1, n2-diag);
  68.             xstart=  ystart - nv + diag;
  69.             
  70.                     /* Compare the two sequences along this diagonal
  71.                         and fill in matchVec while clearing pointVec */
  72.             matchp= matchvec;
  73.             hp= &(hseq[xstart]); 
  74.             vp= &(vseq[ystart]);  
  75.             for (i= ystart; i<= yfinish; i++) {
  76.               *(matchp++)= (*(hp++) == *(vp++));
  77.                 }    
  78.             
  79.          /*!!! ^^^^^ revise this & data store to find/keep line segments !!! */
  80.          /* if matchp[i] && matchp[i-1] ... */
  81.          
  82.                   /* clear a window's width at the end */
  83.              for (i= 0; i<window; i++) *(matchp++)= 0;        
  84.             
  85.                         /* Count the number of matches in the first window */
  86.             for (i=0, matchp= matchvec, matches=0; i<window; i++) {
  87.                 if (*(matchp++)) matches++;
  88.                 }
  89.                 
  90.                     /* step window along  diagonal, transfer comparison 
  91.                         results    to pointVec when nMatch is met.    */
  92.             h = xstart;  
  93.             v = nv - ystart;
  94.             if (!allpts) { h += halfwind; v -= halfwind; }
  95.             for (i=lasti=0; i< yfinish-ystart-window; i++) {            
  96.                 if (matches >= nmatch) {    
  97.                 
  98.               if (allpts) {
  99.                         for (j= max(i,lasti); j<i+window; j++) {
  100.                             if (matchvec[j]) {
  101.                               /* dodot(j);  */
  102.                                 if (npic >= maxpic) {     
  103.                                     maxpic += 100;  
  104.                                     SetHandleSize((Handle)pich, maxpic*sizeof(long)); 
  105.                                     if (MemError() != 0) goto done;    
  106.                                     }    
  107.                                 (*pich)[npic++] = (h+j) + ((v-j)<<16);    
  108.                                 }
  109.                             }
  110.                         lasti= i+window;
  111.                         }
  112.                         
  113.                     else {    /* MoveTo( h + i, v - i); Line(0, 0); */     
  114.                       /* dodot(i); */
  115.                         if (npic >= maxpic) {     
  116.                             maxpic += 100;  
  117.                             SetHandleSize((Handle)pich, maxpic*sizeof(long)); 
  118.                             if (MemError() != 0) goto done;    
  119.                             }    
  120.                       (*pich)[npic++] = (h+i) + ((v-i)<<16);
  121.                         }
  122.                     }
  123.                 matches += (matchvec[i + window] - matchvec[i]);
  124.                 }
  125.             } /* diag */
  126.             
  127.     done:            
  128.     DisposPtr( matchvec);    
  129.         SetHandleSize((Handle)pich, npic*sizeof(long));
  130.         return;
  131. } /* windowpt */
  132.             
  133.             
  134.  
  135.